package dados;

import java.sql.SQLException;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateConnection {
	private static SessionFactory sessionFactory;
	
	static{
		try {
			AnnotationConfiguration acfg = new AnnotationConfiguration();
			acfg.configure();
			sessionFactory = acfg.buildSessionFactory();
		} catch (Throwable ex) {
			throw new ExceptionInInitializerError(ex);
		}		
	}
	
	public static Session getSession() throws SQLException{
		return sessionFactory.openSession();
	}
	
	public static void main(String args[]) throws SQLException{
		Session s = getSession();
		System.out.println("Connected!");
	}
}
